package com.ruoyi.location.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.location.repository.LoginRepository;
import com.ruoyi.location.repository.generator.entity.LocationUserInfo;
import com.ruoyi.location.service.AppService;
import com.ruoyi.location.vo.req.LoginReq;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/location/login/")
public class LoginController extends BaseController {

    @Autowired
    private AppService appService;
    @Autowired
    private LoginRepository loginRepository;

    @GetMapping("/getMsgAuthCode")
    public AjaxResult getMsgAuthCode(@RequestParam Long phoneNum) {
        appService.getMsgAuthCode(phoneNum);
        return success();
    }

    @PostMapping("/login")
    @ResponseBody
    public AjaxResult login(@RequestBody LoginReq loginReq)
    {
        Map<String, String> data = appService.loginByPhoneNumAndMsgCode(loginReq);
        return AjaxResult.success(data);
    }

    @GetMapping("/getUserInfo")
    public AjaxResult getUserInfo() {
        SysUser user = ShiroUtils.getSysUser();
        LocationUserInfo userInfo = loginRepository.getUserInfo(user.getUserId());
        return success(userInfo);
    }

}
